<?php
namespace app\api\controller;

use app\extra\ApiToken;
use Think\Db;

/**
 * @title 广告管理
 * @description 接口说明
 * @group api
 */
class Advert extends Base
{

    /**
     * @title 广告获取(get)
     * @description 接口说明     
     * @author hardy
     * @url /api/advert
     * @method GET
     *
     * @param name:place type:int require: default:1 other: desc:默认为pc端1 pc端，2 移动端
     *
     *
     * @return title:广告标题
     * @return link:跳转链接
     * @return photo_link:广告图片
     * @return page_view:浏览量
     * @return init_view:初始浏览量
     * @return capacity:加载量
     * @return place:广告位置，1 pc端，2 移动端
     * @return publish:0待发布，1已发布，2已下架
     * @return create_time:创建时间
     */
    public function gets()
    {
        $place = input('get.place', 1);
         $where[] = ['publish','=', 1];
        $where[] = ['place','=', $place];

        $data = model($this->controller)->randomOneData($where);
        if(empty($data)){
            $this->responseSuccess(null);
        }
        $data->capacity += 1;
        $data->page_view += 1;
        if ($data->max_capacity <= $data->capacity){
            $data->publish = 2;
        }
        $data->save();
        $this->responseSuccess($data);
    }
}